﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Marmat.Forms.Skin
{
    partial class ButtonGroup
    {
        /// <summary>
        /// 获取默认大小
        /// </summary>
        protected override Size DefaultSize => new Size(150, 25);

        /// <summary>
        /// 获取或设置自动大小
        /// </summary>
        [Browsable(true)]
        [DefaultValue(false)]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public override bool AutoSize
        {
            get => this._autoSize;
            set
            {
                this._autoSize = value;
                this.RefreshSize();
            }
        }
        private bool _autoSize;

        /// <summary>
        /// 获取或设置圆角，如果为true则 Circle 属性设置无效
        /// </summary>
        [Category("样式"), Description("是否开启圆角按钮，如果为true则 Circle 属性设置无效")]
        [DefaultValue(false)]
        public bool Round
        {
            get => this.round;
            set
            {
                if (this.round != value)
                {
                    this.round = value;
                    this.Invalidate();
                }
            }
        }
        private bool round;


        /// <summary>
        /// 获取 GroupButton 中的项
        /// </summary>
        [Category("数据"), Description("GroupButton 中的项")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public ButtonGroupItemCollection Buttons { get; }

        /// <summary>
        /// 在单击 ButtonGroupItem 后发生
        /// </summary>
        [Category("样式"), Description("在单击 ButtonGroupItem 后发生")]
        public event EventHandler<ButtonGroupEventArgs> ItemClicked;

        /// <summary>
        /// 获取或设置 按钮组的圆角程度（不能超过控件高度的一半）
        /// </summary>
        [Category("样式"), Description("按钮组的圆角程度（不能超过控件高度的一半）")]
        [DefaultValue(0)]
        public int Circle
        {
            get => this._circle;
            set
            {
                if (_circle != value)
                {
                    value = Math.Max(value, 0);
                    var size = Math.Min(this.Height, this.Width) / 2;
                    if (value > size)
                        value = size;
                    this._circle = value;
                    this.Invalidate();
                }
            }
        }
        private int _circle = 0;

        //储存矩形
        private Dictionary<ButtonGroupItem, Rectangle> rectangleDec = new Dictionary<ButtonGroupItem, Rectangle>();
        //鼠标位置
        private Point point = new Point(-1, -1);
        //点击的按钮
        private ButtonGroupItem clickButton;
    }
}
